<?php

/*
 * To change this template, choose Tools | Templates
* and open the template in the editor.
*/
require 'connection.php';

try {
	$con = connect();

	$notificationId = $_POST['notificationId'];
	$cityId = $_POST['cityId'];
	$date = $_POST['date'];

	if($notificationId != '' && $cityId != ''){

		$sql = "INSERT INTO notificacion_ciudad (ciudad, notificacion, fechaenvio)
				VALUES (".$cityId.", ".$notificationId.", '".$date."')
						ON DUPLICATE KEY UPDATE fechaenvio = '".$date."'";

		if($con->query($sql)){
			$sqlUpdate = "UPDATE notificacion SET estado = '2' WHERE idnotificacion = '".$notificationId."'";
				
			if($con->query($sqlUpdate)){
				echo 'successful';
			}else{
				echo 'error actualizando la notificacion';
			}
		}else{
			echo 'error asociando la notificacion con la ciudad';
		}

	}else{
		echo 'error';
	}
	mysqli_close($con);
}catch (Exception $e){
	echo $e->getMessage();
}


?>
